/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jdl_ChangeStaffInfo.java
 *
 * Created on Aug 11, 2010, 10:25:44 AM
 */

package GUI;

import GUI.Staff_login;
import config.Database_function;
import config.Function;
import config.User_function;
import java.awt.Frame;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;

/**
 *
 * @author RYUDO
 */
public class jdl_ChangeStaffInfo extends javax.swing.JDialog {
      ResultSet  staff_info;
      String username;
      String role;
      String real_role;
      Frame get_parent;
    /** Creates new form jdl_ChangeStaffInfo */
    public jdl_ChangeStaffInfo(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }


    public jdl_ChangeStaffInfo(java.awt.Frame parent, boolean modal,String role,String username,boolean alledit) throws ParseException, SQLException {
        super(parent, modal);
        initComponents();
        this.username = username;
        this.role = role;
        this.real_role = User_function.check_role(role);
        Function.Windows_centered(this.getWidth(), this.getHeight(), this);
         if (role.equalsIgnoreCase("Administrator")) {
            staff_info = User_function.get_staff_info(username, "tbl_Admin");
        } else {
             staff_info = User_function.get_staff_info(username, "tbl_Staff");
             if(!alledit) {
                 this.txtEmail.setEditable(false);
             }   
        }
        this.get_parent = parent;
        set_info();
    }

    private void set_info() throws ParseException, SQLException {
        this.lblUser.setText(staff_info.getString(1));
        this.txtFirstName.setText(staff_info.getString(2));
        this.txtLastName.setText(staff_info.getString(3));
        this.txtPhone.setText(staff_info.getString(4));
        if(Function.get_gender(staff_info.getString(5)).equalsIgnoreCase("Male")) {
            this.comGender.setSelectedIndex(0);
        } else {
            this.comGender.setSelectedIndex(1);
        }
      this.txtBirthDay.setDate(staff_info.getDate(6));
      this.txtEmail.setText(staff_info.getString(9));
        this.txtAddress.setText(staff_info.getString(8));
        
    }

    public void change_staff_detail(String table,String username) {
       String gender = this.comGender.getSelectedItem().toString();
       boolean bit_gender;
       if(gender.equals("Male")) {
            bit_gender = true;
       } else {
           bit_gender = false;
       }
        try {

            Connection cn = Database_function.setConnection();
            PreparedStatement pst = cn.prepareStatement("UPDATE "+table+" SET FirstName = ?,LastName = ?,Phone = ?,Gender = ?,Birthday = ?,Address = ?,Email = ? WHERE username = '"+username+"'");
            pst.setString(1, this.txtFirstName.getText());
            pst.setString(2, this.txtLastName.getText());
            pst.setString(3, this.txtPhone.getText());
            pst.setBoolean(4, bit_gender);
            pst.setString(5, this.txtBirthDay.getCalendar().getTime().toLocaleString());
            pst.setString(6, this.txtAddress.getText());
            pst.setString(7, this.txtEmail.getText());
            if(pst.executeUpdate()!= 0)
            {
                JOptionPane.showMessageDialog(null, "Update detail successfully");
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(null, "Error with the database, update detail failed");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDateChooserBeanInfo1 = new com.toedter.calendar.JDateChooserBeanInfo();
        jSpinField1 = new com.toedter.components.JSpinField();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        pnPass = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        btnChangePass = new javax.swing.JButton();
        txtOldPass = new javax.swing.JPasswordField();
        txtReNewPass = new javax.swing.JPasswordField();
        txtNewPass = new javax.swing.JPasswordField();
        btnReset1 = new javax.swing.JButton();
        lblUser = new javax.swing.JLabel();
        pnPersonalInfo = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        btnChangeInfo = new javax.swing.JButton();
        btnReset2 = new javax.swing.JButton();
        txtFirstName = new javax.swing.JTextField();
        txtLastName = new javax.swing.JTextField();
        txtPhone = new javax.swing.JTextField();
        comGender = new javax.swing.JComboBox();
        txtBirthDay = new com.toedter.calendar.JDateChooser();
        lblEmail = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtAddress = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel3.setBackground(new java.awt.Color(213, 228, 242));
        jPanel3.setForeground(new java.awt.Color(240, 240, 240));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setForeground(new java.awt.Color(9, 32, 90));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Edit-icon.png"))); // NOI18N
        jLabel1.setText("Edit Personal Information");
        jLabel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        pnPass.setBorder(javax.swing.BorderFactory.createTitledBorder("Change Password"));
        pnPass.setForeground(new java.awt.Color(240, 240, 240));
        pnPass.setOpaque(false);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setText("Username:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setText("Old Password:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel4.setText("New Password:");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel5.setText("Re-type New Password:");

        btnChangePass.setText("Change");
        btnChangePass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChangePassActionPerformed(evt);
            }
        });

        btnReset1.setText("Reset");
        btnReset1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReset1ActionPerformed(evt);
            }
        });

        lblUser.setText("jLabel6");

        javax.swing.GroupLayout pnPassLayout = new javax.swing.GroupLayout(pnPass);
        pnPass.setLayout(pnPassLayout);
        pnPassLayout.setHorizontalGroup(
            pnPassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnPassLayout.createSequentialGroup()
                .addGap(101, 101, 101)
                .addGroup(pnPassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnPassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel2)
                        .addComponent(jLabel3)
                        .addComponent(jLabel4)
                        .addComponent(jLabel5))
                    .addComponent(btnChangePass))
                .addGap(18, 18, 18)
                .addGroup(pnPassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnPassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtReNewPass)
                        .addComponent(txtNewPass)
                        .addComponent(txtOldPass, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lblUser)
                    .addComponent(btnReset1))
                .addContainerGap(111, Short.MAX_VALUE))
        );
        pnPassLayout.setVerticalGroup(
            pnPassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnPassLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnPassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lblUser))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnPassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtOldPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnPassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtNewPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnPassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtReNewPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnPassLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnReset1)
                    .addComponent(btnChangePass))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnPersonalInfo.setBorder(javax.swing.BorderFactory.createTitledBorder("Personal Information"));
        pnPersonalInfo.setOpaque(false);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel6.setText("First Name:");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel7.setText("Last Name:");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel8.setText("Phone:");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel9.setText("Gender:");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel10.setText("Birthday:");

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel11.setText("Address:");

        btnChangeInfo.setText("Change");
        btnChangeInfo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChangeInfoActionPerformed(evt);
            }
        });

        btnReset2.setText("Reset");
        btnReset2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReset2ActionPerformed(evt);
            }
        });

        comGender.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Male", "Female" }));

        lblEmail.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblEmail.setText("Email:");

        txtAddress.setColumns(20);
        txtAddress.setRows(5);
        jScrollPane1.setViewportView(txtAddress);

        javax.swing.GroupLayout pnPersonalInfoLayout = new javax.swing.GroupLayout(pnPersonalInfo);
        pnPersonalInfo.setLayout(pnPersonalInfoLayout);
        pnPersonalInfoLayout.setHorizontalGroup(
            pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnPersonalInfoLayout.createSequentialGroup()
                .addGroup(pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnPersonalInfoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(pnPersonalInfoLayout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addGap(18, 18, 18)
                                .addComponent(comGender, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(pnPersonalInfoLayout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnPersonalInfoLayout.createSequentialGroup()
                                .addGroup(pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel7))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(txtFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtLastName, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(lblEmail)
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                            .addComponent(txtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                            .addComponent(txtBirthDay, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)))
                    .addGroup(pnPersonalInfoLayout.createSequentialGroup()
                        .addGap(176, 176, 176)
                        .addComponent(btnChangeInfo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnReset2)))
                .addContainerGap())
        );
        pnPersonalInfoLayout.setVerticalGroup(
            pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnPersonalInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtBirthDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblEmail)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnPersonalInfoLayout.createSequentialGroup()
                        .addGroup(pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(comGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnPersonalInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnChangeInfo)
                    .addComponent(btnReset2))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(pnPersonalInfo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)
                    .addComponent(pnPass, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnPersonalInfo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnReset2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReset2ActionPerformed
        Function.resetComponents(null, this.pnPersonalInfo);
    }//GEN-LAST:event_btnReset2ActionPerformed

     public boolean check_unique(String username,String table) {
       boolean check = true;
        try {

            Connection cn = Database_function.setConnection();
            Statement st = cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            ResultSet rs = st.executeQuery("SELECT username FROM "+table+"");
            while(rs.next()) {
                if(rs.getString("username").equalsIgnoreCase(username)) {
                    check = false;
                }
            }
        } catch (SQLException ex) {
            Logger.getLogger(jdl_addStaff.class.getName()).log(Level.SEVERE, null, ex);
        }
        return check;
    }

     public boolean check_personal_info(String username,String table) {
        boolean check = true;
        Date d = new Date();
        String date = Function.date_converter("yyyy-MM-dd", d);
        String birth_date = Function.date_converter("yyyy-MM-dd", this.txtBirthDay.getDate());
        
        if(!Pattern.matches("^\\w[A-Za-z\\s]+\\w$", this.txtFirstName.getText()) || !Pattern.matches("\\w[A-Za-z\\s]+\\w$", this.txtLastName.getText())) {
            JOptionPane.showMessageDialog(null, "Lastname or Firstname is invalid !\nHint: No space from the begin and the end and no special character");
            check = false;
        
        } else if (!Pattern.matches("^\\S+.+@.+\\.[a-z]+", this.txtEmail.getText())) {
            JOptionPane.showMessageDialog(null, "Email is invalid !");
            check = false;
        } else if(!Pattern.matches("^[0-9]+$", this.txtPhone.getText())) {
            JOptionPane.showMessageDialog(null, "Phone is invalid !\nHint: Number only");
            check = false;
        } else if(!Pattern.matches("^\\S+.+$", this.txtAddress.getText())) {
            JOptionPane.showMessageDialog(null, "Address is invalid !");
            check = false;
        }
        else if(this.txtBirthDay.getDate() == null) {
             JOptionPane.showMessageDialog(null, "You must enter birthday");
             check = false;
        } else if(birth_date.equals(date) || this.txtBirthDay.getDate().after(d)) {
             JOptionPane.showMessageDialog(null, "Your birthday is not equals or larger than the current day");
            check = false;
        } 

        return check;
    }

     public boolean check_login_info(String username,String table) {
         boolean check = true;
         if(!Pattern.matches("^\\w+.+\\S+$", String.valueOf(this.txtNewPass.getPassword())) || !Pattern.matches("^\\w+.+\\S+$", String.valueOf(this.txtReNewPass.getPassword()))) {
            JOptionPane.showMessageDialog(null, "Password is invalid !\nHint: No space and non-word character");
            check = false;

        }  else if(!String.valueOf(this.txtNewPass.getPassword()).equals(String.valueOf(this.txtReNewPass.getPassword()))) {
            JOptionPane.showMessageDialog(null, "Your password doesnt match");
            check = false;
        }
         return check;
     }


    private void btnChangeInfoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChangeInfoActionPerformed
         if(check_personal_info(this.username,real_role)) {
            if (role.equalsIgnoreCase("Administrator")) {
                try {
                    this.change_staff_detail("tbl_Admin", username);
                    jdl_staffInfo sf = new jdl_staffInfo(null, true, role, username);
                    sf.setVisible(true);
                    this.dispose();
                } catch (ParseException ex) {
                    Logger.getLogger(jdl_ChangeStaffInfo.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(jdl_ChangeStaffInfo.class.getName()).log(Level.SEVERE, null, ex);
                }

             } else {
                try {
                    this.change_staff_detail("tbl_Staff", username);
                    jdl_staffInfo sf = new jdl_staffInfo(null, true, role, username);
                    sf.setVisible(true);
                    this.dispose();
                } catch (ParseException ex) {
                    Logger.getLogger(jdl_ChangeStaffInfo.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(jdl_ChangeStaffInfo.class.getName()).log(Level.SEVERE, null, ex);
                }
             }
        }
    }//GEN-LAST:event_btnChangeInfoActionPerformed

    private void btnChangePassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChangePassActionPerformed
         if(check_login_info(this.username,real_role)) {
            if (role.equalsIgnoreCase("Administrator")) {
                    try {
                        if (String.valueOf(this.txtOldPass.getPassword()).equals(staff_info.getString(10))) {
                            if (String.valueOf(this.txtNewPass.getPassword()).equals(String.valueOf(this.txtReNewPass.getPassword()))) {
                                User_function.change_staff_password("tbl_Admin", username, String.valueOf(this.txtNewPass.getPassword()));
                                Staff_login sf = new Staff_login();
                                sf.setVisible(true);
                                this.dispose();
                                
                                
                            } else {
                                JOptionPane.showMessageDialog(null, "New Password not match");
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "Old Password not match");
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(jdl_ChangeStaffInfo.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    try {
                        if (String.valueOf(this.txtOldPass.getPassword()).equals(staff_info.getString(10))) {
                            if (String.valueOf(this.txtNewPass.getPassword()).equals(String.valueOf(this.txtReNewPass.getPassword()))) {
                                User_function.change_staff_password("tbl_Staff", username, String.valueOf(this.txtNewPass.getPassword()));
                                Staff_login sf = new Staff_login();
                                sf.setVisible(true);
                                this.dispose();
                               
                                
                            } else {
                                JOptionPane.showMessageDialog(null, "New Password not match");
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "Old Password not match");
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(jdl_ChangeStaffInfo.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
        }


    }//GEN-LAST:event_btnChangePassActionPerformed

    private void btnReset1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReset1ActionPerformed
        Function.resetComponents(null, pnPass);
    }//GEN-LAST:event_btnReset1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                jdl_ChangeStaffInfo dialog = new jdl_ChangeStaffInfo(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChangeInfo;
    private javax.swing.JButton btnChangePass;
    private javax.swing.JButton btnReset1;
    private javax.swing.JButton btnReset2;
    private javax.swing.JComboBox comGender;
    private com.toedter.calendar.JDateChooserBeanInfo jDateChooserBeanInfo1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private com.toedter.components.JSpinField jSpinField1;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblUser;
    private javax.swing.JPanel pnPass;
    private javax.swing.JPanel pnPersonalInfo;
    private javax.swing.JTextArea txtAddress;
    private com.toedter.calendar.JDateChooser txtBirthDay;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtFirstName;
    private javax.swing.JTextField txtLastName;
    private javax.swing.JPasswordField txtNewPass;
    private javax.swing.JPasswordField txtOldPass;
    private javax.swing.JTextField txtPhone;
    private javax.swing.JPasswordField txtReNewPass;
    // End of variables declaration//GEN-END:variables

}
